<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
    {% load static %}
    {% csrf_token %}
</head>
<body>
<div class="container-fluid">
    <div class="row">
        <div class="col-md-8 col-md-offset-2">
            <h1 class="text-center">登陆</h1>
            <div class="form-group">
                <label for="username">用户名</label>
                <input type="text" name="username" id="username" class="form-control">
            </div>
            <div class="form-group">
                <label for="password">密码</label>
                <input type="password" name="password" id="password" class="form-control">
            </div>
            <div class="form-group">
                <label for="id_code">验证码</label>
                <div class="row">
                    <div class="col-md-6">
                        <input type="text" name="code" id="id_code" class="form-control">
                    </div>
                    <div class="col-md-6">
                        <img src="/get_code/" alt="" width="430" height="35" id="id_img">
                    </div>
                </div>
            </div>
            <input type="button" class="btn btn-success" value="登陆" id="id_submit">
            <span style="color: red"></span>
        </div>
    </div>
</div>
<script src="{% static 'js/mysetup.js' %}"></script>
<script>
    $('#id_img').click(function () {
        let obj = $(this).attr('src');
        $(this).attr('src', obj += '*')
    });

    $('#id_submit').click(function () {
       let username = $('#username').val();
       let password = $('#password').val();
       let code = $('#id_code').val();
       $.ajax({
           url: '',
           type: 'post',
           data: {'username': username, 'password': password, 'code': code},
           success: function (args) {
                if(args.code === 1000){
                    window.location.href = args.url
                }else if (args === 1001){
                    $('#id_submit').next().text(args.msg);
                }else{
                    $('#id_submit').next().text(args.msg);
                }
           }
       })
    })
</script>
</body>
</html>